package com.linfeng.component.common.response;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class ResponseEntitySerializer extends StdSerializer<ResponseEntity> {

    public ResponseEntitySerializer() {
        super(ResponseEntity.class);
    }

    @Override
    public void serialize(ResponseEntity responseEntity, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();

        jsonGenerator.writeNumberField("code", responseEntity.getCode());
        jsonGenerator.writeStringField("message", responseEntity.getMessage());
        jsonGenerator.writeObjectField("data", responseEntity.getData());

        jsonGenerator.writeEndObject();
    }
}
